<?php
/**
 * 
 * 特点 支持多语言
 * @author Wolf
 *
 */
class ArticleModule extends Module
{
    protected $_type = 1;
    
    protected $_keys = array(
            'nid',
            'content',
            'lang',
            'title');
    protected $_con;
    
    protected $_temp = array(
            'add' => 'file:module/news.add.tpl',
            'edit' => 'file:module/news.edit.tpl',
            'list' => 'file:news/list.tpl');
    
    /* (non-PHPdoc)
     * @see IModule::remove()
     */
    public function remove($where)
    {
        // TODO Auto-generated method stub
    

    }
    
    /* (non-PHPdoc)
     * @see IModule::edit()
     */
    public function edit($nid)
    {
    
    }
    
    /* (non-PHPdoc)
     * @see Module::listing()
     */
    public function listing($page, $cids, $order)
    {
        // TODO Auto-generated method stub
    

    }
    
    /* (non-PHPdoc)
     * @see Module::save()
     */
    public function save($data, $nid)
    {
        // TODO Auto-generated method stub
        $this->setCon($data);
        $lang = $this->getLang();
        $where = array(
                'nid' => $nid,
                'lang' => $lang['id']);
        $v = $this->getCon($nid);
        
        ModuleModel::instance()->saveModuleCon($v, $where, $this->_type);
    
    }
    
    /* (non-PHPdoc)
     * @see Module::temp()
     */
    public function temp($type)
    {
        // TODO Auto-generated method stub
        return $this->_temp[$type];
    
    }
    /* (non-PHPdoc)
     * @see Module::add()
     */
    public function add($data)
    {
        $this->setCon($data);
        
        ModuleModel::instance()->addModuleCon($this->getCon(0), $this->_type);
    }
    
    /* (non-PHPdoc)
     * @see Module::setCon()
     */
    public function setCon($data)
    {
        $lang = $this->getLang();
        
        foreach ($this->_keys as $v) {
            $this->_con[$v] = $data[$v];
        }
        $this->_con['lang'] = $lang['id'];
    
    }
    /* (non-PHPdoc)
     * @see IModule::getCon()
     */
    public function getCon($nid)
    {
        if (! empty($this->_con))
            return $this->_con;
        
     // TODO Auto-generated method stub
        $lang = $this->getLang();
        $where = array(
                'nid' => $nid,
                'lang' => $lang['id']);
        
        $rs = ModuleModel::instance()->getModuleCon($where);
        
        if (empty($rs)) {
            $rs[0] = array(
                    'title' => 'nothing',
                    'content' => "nothing!");
        }
        return $rs;
    
    }
    
    /**
     * @return the $_lang
     */
    private function getLang()
    {
        $lang = NewsModel::instance()->getLang(array(
                'keyword' => $_COOKIE['lang']));
        return $lang[0];
    
    }

}